define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>是否拒绝？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });

    var _vm = Init.initVue({
        data : {
            trade_no : '',
            list : [],
            id: null,
            cur : 1,
            all : 0,
            search: false,
            check: {},
            show : false,
            assign_w: '',
            assign_q: '',
            result: null,
            type : null,
            status : null,
        },
        methods: {
            reSearch : function() {
                this.search = true;
                this.getData(1);
            },
            reset : function() {
                this.search = false;
                this.trade_no = '';
                this.status = null;
            },
            getData : function(n) {
                var obj = {
                    page: n, num: 10,
                    no : _vm.no,
                    id : _vm.id,
                    status : _vm.status
                };
                METHOD.loading.show();
                METHOD.ajax("apply/operate/detail",obj).done(function(json){
                    METHOD.loading.hide();
                    _vm.list = json.data;
                    _vm.all = json.page.pages;
                }).fail(function(){
                    METHOD.loading.hide();
                });
            },
            operate : function(id) {
                _Dialog.showUI(function(i) {
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax("apply/detail/refuse", { id : id }, {type:"post"}).done(function(json){
                            METHOD.loading.hide();
                            _vm.getData(1);
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }
                    this.hideUI();
                });
            },
            goApply : function() {
                METHOD.loading.show();
                METHOD.ajax("apply/detail/operate", {id:_vm.id}, {type:"post"}).done(function(json){
                    METHOD.loading.hide();
                    METHOD.alert("操作成功").done(function(){
                        window.location.href = "../trade/apply.html";
                    });
                }).fail(function(){
                    METHOD.loading.hide();
                });
            },
            showDeal : function() {
                METHOD.loading.show();
                METHOD.ajax("apply/operate/result", {id:_vm.id}).done(function(json){
                    METHOD.loading.hide();
                    _vm.show = true;
                    _vm.result = json.data;
                    _vm.type = json.data.type;
                }).fail(function(){
                    METHOD.loading.hide();
                });
            },
            cancel : function() {
                this.show = false;
                this.assign_w = '';
                this.assign_q = '';
            },
            preDeal : function() {

                if (_vm.type == 1 && !_vm.assign_w) {
                    METHOD.alert("市值分配量不能为空");
                } else if (_vm.type == 2 && !_vm.assign_q) {
                    METHOD.alert("抢单分配量不能为空");
                } else if (_vm.type == 3) {
                    if (!_vm.assign_w || !_vm.assign_q ) {
                        METHOD.alert("请完善信息，所有内容必填");
                        return;
                    }
                }

                METHOD.loading.show();
                METHOD.ajax("apply/operate/update_result", {
                    id: _vm.id,
                    assign_w: _vm.assign_w,
                    assign_q: _vm.assign_q
                }, {type:"post"}).done(function(json){
                    METHOD.loading.hide();
                    _vm.show = false;
                    METHOD.alert("操作成功").done(function(){
                        _vm.cancel();
                    });
                }).fail(function(){
                    METHOD.loading.hide();
                });
            }
        }
    });

    _vm.id = METHOD.getQueryParms("id") || null;
    _vm.getData(1);

});

